﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using QualityRpt.Service;
using System.Collections;
using QualityRpt.Utils;

namespace QualityRPT.AirwirePlaza
{
    public partial class index : System.Web.UI.Page
    {
        public string PagerHtml = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                DataTable spTable = DeviceSupplierService.GetListSupplierName(string.Empty, string.Empty, DeviceService.AIRWIRE_DEV);
                this.ajax_spin.DataSource = spTable;
                this.ajax_spin.DataTextField = "SUPPLIER_NAME"; this.ajax_spin.DataValueField = "ID";
                this.ajax_spin.DataBind();
                strSpIn = Request.Params["spin"];
                strPage = Request.Params["p"];
                if (strPage == null) { strPage = string.Empty; }
                BindData();
            }
            else
            {
                strSpIn = Request.Params["ajax_spin"];
            }
        }
        public string strSpIn = string.Empty; public string strPage = string.Empty;
        private void BindParams()
        {
            if (strSpIn == null) { strSpIn = string.Empty; }
            //厂商选中状态
            if (strSpIn != null && strSpIn.Trim() != string.Empty)
            {
                string[] selSpin = strSpIn.Split(new char[] { ',' });
                Hashtable hashSelSp = new Hashtable();
                for (int i = 0; i < selSpin.Length; i++)
                {
                    hashSelSp.Add(selSpin[i], 0);
                }
                for (int i = 0; i < ajax_spin.Items.Count; i++)
                {
                    if (hashSelSp.ContainsKey(ajax_spin.Items[i].Value))
                    {
                        ajax_spin.Items[i].Selected = true;
                    }
                }
            }
            if (strPage == string.Empty) { strPage = "1"; }
        }
        protected void ButtonQ_Click(object sender, EventArgs e)
        {
            BindData();
        }
        private void BindData()
        {
            BindParams();
            PageUtils pu = new PageUtils(); pu.PerPageNum = 20; pu.Page = int.Parse(strPage);
            DataTable detailTable = AirwirePlazaService.GetListBySpRd(strSpIn, string.Empty,pu);
            this.repeater_data.DataSource = detailTable;
            this.repeater_data.DataBind();
            PagerHtml = pu.GenStPagination("index.aspx?pid=" + Request.Params["pid"] + "&cid=" + Request.Params["cid"] + "&p={page}&spin=" + strSpIn);
        }
        protected void ButtonAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("edit.aspx?pid=" + Request.Params["pid"] + "&cid=" + Request.Params["cid"]);
        }
    }
}